import router from "@/router"
import store from "@/store"
import {
    MessageBox,
    Message
} from 'element-ui'
// 工具函数：根据 create_time 对数组进行排序
export function sortByCreateTime(arr) {
    return arr.sort((a, b) => new Date(b.create_time) - new Date(a.create_time));
}
// 复制链接
export function copyToClipboard(text) {
    const el = document.createElement('textarea');
    el.value = text;
    document.body.appendChild(el);
    el.select();
    document.execCommand('copy');
    document.body.removeChild(el);
}
// 生成唯一随机数
export function generateUniqueRandomNumber(existingNumbers, min, max) {
    const randomNumbers = new Set(existingNumbers);
    let randomNumber;

    do {
        randomNumber = Math.floor(Math.random() * (max - min + 1)) + min;
    } while (randomNumbers.has(randomNumber));

    randomNumbers.add(randomNumber);
    return randomNumber;
}
export function RequestDealWithModuleList() {
    // 获取模块开关
    const moduleList = store.state.paid.openingModuleList
    if (!moduleList) {
        this.$message.error("获取不到已开启的模块开关")
        return router.push("/login")
    }
    // 如果模块开关被关闭
    if (!moduleList.find(item => item == 'article')) {
        Message({
            message: '博客模块已被关闭',
            type: 'error',
            duration: 5 * 1000
        })
        router.push("/musicScore")
    } else {
        router.push("/article")
    }
}